const mongoose = require('./db');




// 与app客服的聊天记录
const appliaotianSchema = new mongoose.Schema({
    meaname: String, // 用户本人
    youaname: String, //客服本人
    amsg: String,     // 聊天内容
    // 显示实时聊天时间
    atime: {
        type: Date,
        default: Date.now
    }

})
//首页


//浏览历史
const history = new mongoose.Schema({
    classfy: String,/*(房屋类型如整租，单租)*/
    describe: String,/*房屋描述*/
    plot: String,/*小区名称 */
    name: String,/*房屋名称 */
    city: String,/*所在城市 */
    tip: Array,/*（标签如‘临地铁’，‘有阳台’……）*/
    price: String,/*（租金/月）*/
    house_type: String,/*房型（如2室1厅1卫）*/
    house_area: Number,/*房屋面积*/
    house_floor: Number,/*所在楼层*/
    house_direction: String,/*(房屋朝向)*/
    is_collect: {/* 是否收藏*/
        type: Boolean,
        default: false
    },
    add_time: {/*添加时间 */
        type: Date,
        default: Date.now()
    },
    uid: String,//所属登录的用户id
    lid: {/*所属房东 */
        type: mongoose.Types.ObjectId,/* (关联landlord表)*/
        ref: 'landlord'
    },
})



//首页
//房东表
const landlord = new mongoose.Schema({
    photo: String,
    name: String,
    nickname: String,
    phone: Number,
    gender: String,
    uid: {
        type: mongoose.Types.ObjectId,
        ref: 'user'
    },
})
//房屋表
const house = new mongoose.Schema({
    classfy: String,/*(房屋类型如整租，合租/单间)*/
    plot: String,/*小区名称 */
    name: String,/*房屋名称 */
    city: String,/*所在城市 */
    tip: Array,/*（标签如‘临地铁’，‘有阳台’……）家具陈设s*/
    price: String,/*（租金/月）*/
    house_type: String,/*房型（如2室1厅1卫）*/
    house_area: Number,/*房屋面积*/
    house_floor: Number,/*所在楼层*/
    house_direction: String,/*(房屋朝向)*/
    is_collect: {/* 是否收藏*/
        type: Boolean,
        default: false
    },
    add_time: {/*添加时间 */
        type: Date,
        default: Date.now()
    },
    lid: {/*所属房东 */
        type: mongoose.Types.ObjectId,/* (关联landlord表)*/
        ref: 'landlord'
    },
    is_reservation: {/* 是否预约 true是已预约 false是没预约 */
        type: Boolean,
        default: false
    },

    viewing_time: Date,///* 预约时间 */
    house_photo: String,/* 房屋图片 */
    describe: {
        type: String,
        default: '实图真价，精装两房，拎包入住，环境优美，房东好说话'
    },/* 房屋描述 */
    house_status: {//0是默认 1是未出租 2是已出租 3是已下架
        type: Number,
        default: 0
    }

})

// const houseModel = mongoose.model('house', house, 'house');
//预约表
const appointment = new mongoose.Schema({
    person: String,
    phone: String,
    look_time: String,
    say: String,
    appointstatus: { //预约状态 默认值为0表示待定,1表示预约成功，2表示预约失败
        type: Number,
        default: 0
    },
    hid: {//房屋Id
        type: mongoose.Types.ObjectId,
        ref: 'house'
    },
    uid: String,//当前用户的_id

    start__time: {
        type: Date,
        default: Date.now()
    },
    time2: String,
    time3: String,
    time4: String,
    yue_status: {/* 0默认，1，待处理，2未看房，3已完成 4，已拒绝*/
        type: Number,
        default: 0
    },
})


//问题表
const question = new mongoose.Schema({
    question: String,
})



//回答表
const answer = new mongoose.Schema({
    answer: String,
    qid: {
        type: mongoose.Types.ObjectId,
        ref: 'question'
    }
})

// 与房主的聊天记录
const fzliaotianSchema = new mongoose.Schema({
    me: String, // 用户本人
    you: String, //房主本人
    mename: String, // 用户本人内容
    youname: String, //房主本人内容
    msg: String,     // 聊天内容
    // 显示实时聊天时间
    ftime: {
        type: Date,
        default: Date.now
    },
    lid: {
        type: mongoose.Types.ObjectId,
        ref: 'landlord',
    }
})
// 多个用户信息
// 该表用于展示多个用户的聊天记录
const userSchema1 = new mongoose.Schema({
    umeaname: String, // 用户1
    uyouname: String, //用户2
    time: {
        type: Date,
        default: Date.now
    },
    fid: {
        type: mongoose.Types.ObjectId,
        ref: 'fzliaotian',


    },
    aid: {
        type: mongoose.Types.ObjectId,
        ref: 'appliaotian',
    },
    // 关联用户（房东）表
    lid: {
        type: mongoose.Types.ObjectId,
        ref: 'landlord',
    },
})



const fzliaotianModel = mongoose.model('fzliaotian', fzliaotianSchema, 'fzliaotian');
const appliaotianModel = mongoose.model('appliaotian', appliaotianSchema, 'appliaotian');
const userModel = mongoose.model('user', userSchema1, 'user');



//收藏表
const collect = new mongoose.Schema({
    classfy: String,/*(房屋类型如整租，单租)*/
    plot: String,/*小区名称 */
    name: String,/*房屋名称 */
    city: String,/*所在城市 */
    tip: Array,/*（标签如‘临地铁’，‘有阳台’……）*/
    price: String,/*（租金/月）*/
    house_type: String,/*房型（如2室1厅1卫）*/
    house_area: Number,/*房屋面积*/
    house_floor: Number,/*所在楼层*/
    house_direction: String,/*(房屋朝向)*/
    is_collect: {/* 是否收藏*/
        type: Boolean,
        default: false
    },
    add_time: {/*添加时间 */
        type: Date,
        default: Date.now()
    },
    uid: String,//所属登录的用户id
    lid: {/*所属房东 */
        type: mongoose.Types.ObjectId,/* (关联landlord表)*/
        ref: 'landlord'
    },
    viewing_time: Date,///* 发布时间 */
    houseid: String,/*房屋id*/
    describe: {
        type: String,
        default: '实图真价，精装两房，拎包入住，环境优美，房东好说话'
    },/* 房屋描述 */
})



const landlordModel = mongoose.model('landlord', landlord, 'landlord');
const houseModel = mongoose.model('house', house, 'house');
const appointmentModel = mongoose.model('appointment', appointment, 'appointment');
const questionModel = mongoose.model('question', question, 'question');
const answerModel = mongoose.model('answer', answer, 'answer');
const collectModel = mongoose.model('collect', collect, 'collect');
const historyModel = mongoose.model('history', history, 'history')

module.exports = {
    landlordModel,
    houseModel,
    appointmentModel,
    questionModel,
    answerModel,

    fzliaotianModel,
    appliaotianModel,
    userModel,
    collectModel,
    historyModel
}


